<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增')" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-perAppraisalInfo-add">

        <div class="form-group">
            <label class="col-sm-3 control-label">绩效标题：</label>
            <div class="col-sm-8">

                <input id="name" name="name"  class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">绩效模板：</label>
            <div class="col-sm-8">

                <select name="templateId" required class="form-control" id="templateId" th:onchange="change()" th:with="templates=${@template.selectPerTemplateList()}" >
                    <option></option>
                    <option th:each="tepmlate : ${templates}" th:text="${tepmlate.templateName}" th:value="${tepmlate.templateId}" ></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">绩效开始时间：</label>
            <div class="col-sm-8">
                <input id="startTime" name="startTime"  class="form-control time-input" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">绩效结束时间：</label>
            <div class="col-sm-8">
                <input id="endTime" name="endTime"  class="form-control time-input" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <select name="status" id="status" class="form-control" >
                    <option value="disabled">绩效生成待启用</option>
                    <option value="enabled">开启员工自评</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">指定考核员工：</label>
            <div class="col-sm-8">
                <div id="tree" class="ztree treeselect"></div>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<th:block th:include="include :: ztree-js" />
<script th:inline="javascript">

    $(function() {
        var url = ctx + "performance/perAppraisalInfo/userTreeData";
        var options = {
            url: url,
            check: { enable: true, nocheckInherit: true, chkboxType: { "Y": "ps", "N": "ps" } },
            expandLevel: 2,
            onClick : zOnClick
        };
        $.tree.init(options);
    });

    function zOnClick(event, treeId, treeNode) {
        var treeId = treeNode.id;
        var treeName = treeNode.name;
        $("#treeId").val(treeId);
        $("#treeName").val(treeName);
    }
    var prefix = ctx + "performance/perAppraisalInfo"
    $("#form-perAppraisalInfo-add").validate({
        rules:{
            xxxx:{
                required:true,
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var status = $('#status option:selected').val();
            var templateId=$('#templateId').val();
            var userIds=$.tree.getCheckedChildrenNodes();
            var data={'name':$('#name').val(),'templateId':templateId,'startTime':$('#startTime').val(),
                'endTime':$('#endTime').val(),'status':status,'userIds':userIds};
            if(status=='enabled'){
                var url=ctx+'performance/perTemplate/checkWeightLegal/' +templateId;
                $.get(url).successCallback(function (data) {
                    if(data.code==100){
                        $.operate.save(prefix + "/saveFormulate", data);
                    }
                })

            }
            $.operate.save(prefix + "/saveFormulate",data);
        }
    }
    function change() {
        var templateId=$('#templateId option:selected').val();
        if(templateId==''){
            return;
        }
        var url = ctx+'performance/perTemplate/distributeWeight/' +templateId ;
        $.modal.open("分配权重", url);
    }
</script>
</body>
</html>
